﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VeryExtremeArt.Controller;

namespace VeryExtremeArt
{
    public partial class Catalogue : System.Web.UI.Page
    {
        ArtPieceController apc = new ArtPieceController();
        Member memberLoggedIn = null;
        protected void Page_Load(object sender, EventArgs e)
        {

            MemberController mc = new MemberController();
            if (Session["username"] == null || Session["password"] == null)
            {
                Session["message"] = "Only logged in users can see this page";
                Response.Redirect("~/Login.aspx");
            }
            else
            {
                memberLoggedIn = mc.Login(Session["username"].ToString(), Session["password"].ToString());
                if (memberLoggedIn == null)
                {
                    Session["message"] = "Only logged in users can see this page";
                    Response.Redirect("~/Login.aspx");
                }
            }
            // write after this
            AuctionController ac = new AuctionController();
            catalogueItems.DataSource = ac.GetCatalogue();
            catalogueItems.DataBind();


            if (Request.QueryString["bidItemId"] != null && Request.QueryString["bidItemValue"] != null)
            {

                BidController bc = new BidController();
                int artPieceId = Convert.ToInt32(Request.QueryString["bidItemId"]);

                int auctionItemId = apc.GetAuctionItem(artPieceId).Id;
                int auctionId = ac.GetNextAuction().Id;
                int memberId = memberLoggedIn.Id;
                decimal bidValue = Convert.ToDecimal(Request.QueryString["bidItemValue"]);

                bc.placeBid(auctionItemId, memberId, bidValue);
                Response.Redirect("Catalogue.aspx");
            }

        }

        protected void bidButton_Click(object sender, EventArgs e)
        {
            var senderr = sender;
        }

    }
}